home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #1 / Amiga Plus CD - 1997 - No. 01.iso / pd / programmierung / proasm / examples / progressbar / pbtest.s < prev   
Text File  |  1996-04-25  |  7KB  |  343 lines

  1. ;-------------------------------------------------------------------------------
  2. *                                                                              *
  3. * ProgressBar Demo program 'pbtest'                                            *
  4. *                                                                              *
  5. * Written 1995 by Daniel Weber                                                 *
  6. *                                                                              *
  7. *                                                                              *
  8. * Last Revision   16.04.95                                                     *
  9. *                                                                              *
  10. ;-------------------------------------------------------------------------------
  11.  
  12.     output    'ram:pbtest'
  13.  
  14.     opt    o+,q+,ow-,qw-,sw-
  15.     verbose
  16.     base    progbase
  17.  
  18.     filenote    'pbtest, ProgressBar.r Demo program'
  19.  
  20. ;-------------------------------------------------------------------------------
  21.  
  22.     incdir    'include:'
  23.     incdir    'routines:'
  24.  
  25.     include    'intuition/intuition.i'
  26.     include    'dos/dos.i'
  27.     include    libraries/gadtools.i
  28.  
  29.  
  30.     incequ    'LVO.s'
  31.     include    'basicmac.r'
  32.  
  33.  
  34. ;-------------------------------------------------------------------------------
  35.  
  36. version        equr    "0.10"
  37. gea_progname    equr    "pbtest"
  38.  
  39. ;-- startup control  --
  40. cws_V36PLUSONLY    set    1            ;only OS2.x or higher
  41. ;cws_DETACH    set    1            ;detach from CLI
  42. cws_CLIONLY    set    1            ;for CLI usage only
  43. cws_EASYLIB    set    1
  44. ;cws_PRI    equ    0            ;set process priority to 0
  45. ;cws_FPU    set    1
  46. ;cws_STACKSIZE    equ    4096
  47.  
  48. ;-- user definitions --
  49. AbsExecBase    equ    4
  50.  
  51. INTUITION.LIB    equ    1
  52. GRAPHICS.LIB    equ    1
  53. DOS.LIB        equ    1
  54. GADTOOLS.LIB    equ    1
  55.  
  56.  
  57. maximum        equ    60            ; max. value for ProgressBar
  58. step        equ    5            ; step width
  59.  
  60. ;-------------------------------------------------------------------------------
  61. progbase:
  62.     jmp    AutoDetach(pc)
  63.     dc.b    0,"$VER: ",gea_progname," ",version," (",__date2,")",0
  64.     even
  65. ;----------------------------
  66. start:
  67. clistartup:
  68. wbstartup:
  69.     lea    progbase(pc),a5
  70.     bsr    OpenProgressWindow
  71.     tst.l    ProgressWnd(a5)
  72.     beq    .out
  73.  
  74.     lea    pbar(pc),a0
  75.     move.l    ProgressWnd(a5),a1
  76.     move.b    wd_BorderLeft(a1),d0
  77.     ext.w    d0
  78.     move.b    wd_BorderTop(a1),d1
  79.     ext.w    d1
  80.     add.w    d0,pgb_x(a0)
  81.     add.w    d1,pgb_y(a0)
  82.     CALL_    InitProgressBar
  83.     beq    .err
  84.  
  85.     move.l    #maximum,pgb_max(a0)        ; set to 60 seconds
  86.  
  87.  
  88.     ;
  89.     ; play around a bit
  90.     ;
  91.     moveq    #10-1,d6
  92. .loop    move.l    DosBase(pc),a6
  93.     moveq    #4,d1
  94.     jsr    _LVODelay(a6)
  95.     lea    pbar(pc),a0
  96.     move.l    #maximum,pgb_value(a0)
  97.     CALL_    SetProgressBar
  98.     moveq    #4,d1
  99.     jsr    _LVODelay(a6)
  100.     lea    pbar(pc),a0
  101.     clr.l    pgb_value(a0)
  102.     CALL_    ClearProgressBar
  103.     dbra    d6,.loop
  104.  
  105.     ;
  106.     ; fill & empty bar
  107.     ;
  108.     moveq    #step,d7        ; step value
  109.     clr.l    pgb_value+pbar(a5)
  110.     moveq    #1,d6
  111. .loop2    moveq    #maximum/step,d5
  112. .loop3    lea    pbar(pc),a0
  113.     add.l    d7,pgb_value(a0)
  114.     CALL_    UpdateProgressBar
  115.     move.l    DosBase(pc),a6
  116.     moveq    #1,d1            ; 1/25 sec
  117.     jsr    _LVODelay(a6)
  118.     dbra    d5,.loop3
  119.     lea    pbar(pc),a0
  120.     clr.w    pgb_last(a0)
  121.     clr.l    pgb_value(a0)
  122.     CALL_    UpdateProgressBar
  123.     dbra    d6,.loop2
  124.  
  125.  
  126.     ;
  127.     ; count seconds...
  128.     ;
  129.     moveq    #step,d7            ; step value
  130. .wait:    move.l    DosBase(pc),a6
  131.     moveq    #50,d1            ; wait a second
  132.     jsr    _LVODelay(a6)
  133.     move.l    #SIGBREAKF_CTRL_C,d6    ;CTRL-C pressed ?
  134.     moveq    #0,d0
  135.     move.l    d6,d1
  136.     move.l    4.w,a6
  137.     jsr    _LVOSetSignal(a6)    ;set signal
  138.     and.l    d6,d0            ;-: break  0:no break
  139.     bne.s    .err
  140.  
  141.     lea    pbar(pc),a0
  142.     add.l    d7,pgb_value(a0)
  143.     beq.s    0$
  144.     cmp.l    #60,pgb_value(a0)
  145.     blt.s    1$
  146. 0$:    neg.l    d7
  147. 1$:    CALL_    UpdateProgressBar
  148.     bra    .wait
  149.  
  150.  
  151. .err:    bsr    CloseProgressWindow
  152. .out:    moveq    #0,d0
  153.     bra    ReplyWBMsg
  154.  
  155.  
  156.  
  157. ;-------------------------------------------------------------------------------
  158. *
  159. * various subroutines
  160. *
  161. ;-------------------------------------------------------------------------------
  162.             foreset
  163. gsd_screenbuffer:    fo.b    52    ;space for GetScreenData()
  164. gsd_length:        foval        ;length of structure
  165.  
  166. boxleft            EQU    4
  167. boxtop            EQU    3
  168. boxwidth        EQU    160
  169. boxheight        EQU    10
  170. boxborderleft        equ    2    ; border sizes for
  171. boxbordertop        equ    1    ; adjusting...
  172. defwinx            equ    16    ; default window positions
  173. defwiny            equ    16    ;
  174. defwinxy        equ    16    ; default pos x=y=16
  175.  
  176.  
  177. OpenProgressWindow:
  178.     movem.l    d1-d4/a0-a4/a6,-(sp)
  179.     lea    progbase(pc),a5
  180.     clr.l    ProgressWnd(a5)
  181.     move.l    IntBase(pc),a6
  182.     sub.l    a0,a0
  183.     jsr    _LVOLockPubScreen(a6)
  184.     move.l    d0,PubScreenLock(a5)
  185.  
  186.     link    a3,#gsd_length        ;get correct title y size
  187.     lea    gsd_screenbuffer(a3),a0
  188.     moveq    #48,d0
  189.     moveq    #1,d1
  190.     sub.l    a1,a1
  191.     jsr    -426(a6)        ;getscreendata()
  192.     lea    gsd_screenbuffer(a3),a0
  193.     moveq    #0,d0
  194.     moveq    #0,d2
  195.     moveq    #0,d3
  196.     move.b    sc_WBorLeft(a0),d2
  197.     move.b    sc_WBorTop(a0),d0
  198.     move.l    sc_Font(a0),a0        ;ptr on TextAttr
  199.     move.w    ta_YSize(a0),d3        ;y font size
  200.     unlk    a3
  201.     subq.w    #8,d3
  202.     ext.l    d3
  203.     add.l    d3,ProgressH+4(a5)
  204.     move.l    d3,ydiff(a5)
  205.     move.l    IntBase(pc),a6
  206.     suba.l    a0,a0
  207.     lea.l    ProgressWindowTags(pc),a1
  208.     jsr    _LVOOpenWindowTagList(a6)
  209.     move.l    d0,ProgressWnd(a5)
  210.     bne.s    .ok
  211.  
  212.     moveq    #defwinxy,d0
  213.     move.l    d0,ProgressL+4(a5)
  214.     move.l    d0,ProgressT+4(a5)
  215.     suba.l    a0,a0
  216.     lea.l    ProgressWindowTags(pc),a1
  217.     jsr    _LVOOpenWindowTagList(a6)
  218.     move.l    d0,ProgressWnd(a5)
  219.     beq.s    .error
  220.  
  221. .ok    move.l    GadToolsBase(pc),a6
  222.     move.l    ProgressWnd(pc),a0
  223.     suba.l    a1,a1
  224.     jsr    _LVOGT_RefreshWindow(a6)
  225.  
  226.     move.l    PubScreenLock(pc),a0
  227.     lea    TD(pc),a1
  228.     jsr    _LVOGetVisualInfoA(a6)
  229.     move.l    d0,VisualInfo(a5)
  230.  
  231.     bsr    ProgressRender
  232.  
  233. .done:    move.l    PubScreenLock(pc),d0
  234.     beq.s    9$
  235.     move.l    d0,a1
  236.     sub.l    a0,a0
  237.     move.l    IntBase(pc),a6
  238.     jsr    _LVOUnlockPubScreen(a6)
  239. 9$:    movem.l    (sp)+,d1-d4/a0-a4/a6
  240.     rts
  241. .error:    moveq    #4,d0
  242.     bra.s    .done
  243.  
  244.  
  245.  
  246. CloseProgressWindow:
  247.     movem.l    d0-d1/a0-a1/a6,-(sp)
  248.     lea    progbase(pc),a5
  249.     move.l    IntBase(pc),a6
  250.     move.l    ProgressWnd(pc),d0
  251.     beq.s    1$
  252.     move.l    d0,a0
  253.     jsr    _LVOCloseWindow(a6)
  254.     clr.l    ProgressWnd(a5)
  255. 1$:    movem.l    (sp)+,d0-d1/a0-a1/a6
  256.     rts
  257.  
  258.  
  259. ;---------------------------------------
  260. ProgressRender:
  261.     movem.l    d0-d5/a0-a2/a6,-(sp)
  262.     move.l    ProgressWnd(pc),d0
  263.     beq    .done
  264.     move.l    d0,a0
  265.  
  266.     move.l    VisualInfo(pc),d0
  267.     move.l    d0,NR+4(a5)
  268.     move.l    d0,IR+4(a5)
  269.  
  270.     move.b    wd_BorderLeft(a0),d0
  271.     ext.w    d0
  272.     move.b    wd_BorderTop(a0),d1
  273.     ext.w    d1
  274.     addq.w    #boxleft,d0        ; left
  275.     addq.w    #boxtop,d1        ; top
  276.     move.w    #boxwidth,d2        ; width
  277.     moveq    #boxheight,d3        ; height
  278.     move.l    ProgressWnd(pc),a0
  279.     move.l    wd_RPort(a0),a0
  280.     lea    IR(pc),a1
  281.     move.l    GadToolsBase(pc),a6
  282.     jsr    _LVODrawBevelBoxA(a6)
  283. .done:    movem.l    (sp)+,d0-d5/a0-a2/a6
  284.     rts
  285.  
  286.  
  287. ;-------------------------------------------------
  288. NR:    DC.L    GT_VisualInfo,$00000000,TAG_DONE
  289. IR:    DC.L    GT_VisualInfo,$00000000,GTBB_Recessed,1
  290. TD:    DC.L    TAG_DONE
  291.  
  292. ProgressWindowTags:
  293. ProgressL:
  294.     DC.L    WA_Left,defwinx
  295. ProgressT:
  296.     DC.L    WA_Top,defwiny
  297. ProgressW:
  298.     DC.L    WA_Width,176
  299. ProgressH:
  300.     DC.L    WA_Height,19+10
  301.     DC.L    WA_IDCMP,IDCMP_CLOSEWINDOW!IDCMP_REFRESHWINDOW
  302.     DC.L    WA_Flags,WFLG_DRAGBAR!WFLG_DEPTHGADGET!WFLG_SMART_REFRESH
  303.     DC.L    WA_Title,ProgressWTitle
  304.     DC.L    TAG_DONE
  305.  
  306. ProgressWTitle:
  307.     dc.b    'PBTest (CTRL-C to quit)...',0
  308.     EVEN
  309.  
  310.  
  311.  
  312. VisualInfo:    dc.l    0
  313. PubScreenLock:    dc.l    0
  314. ProgressWnd:    dc.l    0
  315. ydiff:        dc.l    0
  316.  
  317.  
  318.  
  319. ;-------------------------------------------------------------------------------
  320. *
  321. * external routines
  322. *
  323. ;-------------------------------------------------------------------------------
  324.     include    startup4.r
  325.     include    progressbars.r
  326.  
  327.  
  328. ;-------------------------------------------------------------------------------
  329. *
  330. * data area
  331. *
  332. ;-------------------------------------------------------------------------------
  333.  
  334.  
  335. bar1_x        EQU    boxleft+boxborderleft
  336. bar1_y        EQU    boxtop+boxbordertop
  337. bar1_width    EQU    boxwidth-2*boxborderleft
  338. bar1_height    EQU    boxheight-2*boxbordertop
  339.  
  340. pbar:    ProgressStruct_    bar1,maximum
  341.  
  342.     end
  343.